package com.nkzy.mapper;

import com.nkzy.pojo.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface ArticleMapper {

    @Select("SELECT * FROM article WHERE id = #{id}")
    Article selectById(Integer id);

    @Select("SELECT * FROM article")
    List<Article> selectAll();

    @Insert("INSERT INTO article(title, content, cover_img, state, category_id, create_user, create_time, update_time) " +
            "VALUES(#{title}, #{content}, #{coverImg}, #{state}, #{categoryId}, #{createUser}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Article article);

    @Update("UPDATE article SET title = #{title}, content = #{content}, cover_img = #{coverImg}, state = #{state}, " +
            "category_id = #{categoryId}, create_user = #{createUser}, update_time = #{updateTime} WHERE id = #{id}")
    void update(Article article);

    @Delete("DELETE FROM article WHERE id = #{id}")
    void deleteById(Integer id);
}